package com.szdvte.news.util;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

public class WiterUtil 
{
	//向前台输出数据
	public static void witer(Object obj)
	{
		JSONArray jsonArray=JSONArray.fromObject(obj);
		response(jsonArray.toString());
	}
	public static void witer(Object obj,String name)
	{
		JSONObject jsonObject = new JSONObject();
		jsonObject.put(name, JSONArray.fromObject(obj));
		response(jsonObject.toString());
		
	}
	public static void response(String msg)
	{
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/plain;charset=utf-8");
		try 
		{
			response.getWriter().write(msg);
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
	public static String parseData(Date data)
	{
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		return format.format(data);
	}
}
